<?php
/**
 * Author:xsc
 * Time:2023/11/22 15:15
 */

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Common\Constant;
use App\Extensions\Common\RedisService;
use App\Jobs\CheckMerchantsCallbackJob;
use Illuminate\Support\Facades\Log;

class CheckMerchantsCallback extends Command
{

    /**
     * 命令名称
     */
    protected $signature = 'check_merchants_callback';

    /**
     * 命令描述
     */
    protected $description = '创作者入驻申请审核回调';

    /**
     * 创建命令
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 执行命令
     */
    public function handle()
    {
        $time = time();
        $redis = RedisService::getInstance();
        $key = Constant::CHECK_MERCHANTS_CALLBACK;

        while (1) {
            if (time() > $time + 59) {
                break;
            }

            $id = $redis->lIndex($key, 0);

            if ($id) {
                Log::info('[创作者入驻申请审核回调]脚本' . $id);

                // 异步队列里面执行
                dispatch(new CheckMerchantsCallbackJob($id));
                $redis->lPop($key);
            } else {
                sleep(1);
                //usleep(500000);
            }
        }
    }
}
